<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>滚动进度</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }

        body {
            height: 3000px;
        }

        .line {
            position: fixed;
            top: 0;
            left: 0;
            width: 30px;
            height: 15px;
            background-image: linear-gradient(to right, #f00, #ff0);
        }
    </style>
</head>
<body>
    <div class="line"></div>
    
    <script type="text/javascript">
        /* 
            进度条当前宽度             页面卷入高度
        ---------------------- = ---------------------
           页面可视区域宽度          页面最大可卷入高度

        滚动条整体 = 页面高度
        滚动条阴影部分 = 可视区域高度

        页面最大可卷入高度 = 页面高度 - 可视区域高度
        */

        var maxScroll = document.body.scrollHeight - document.documentElement.clientHeight;

        var line = document.querySelector(".line");

        window.onscroll = function (){
            var sct = window.pageYOffset;
            line.style.width =  sct / maxScroll * 100 + "%";
        }
    </script>
</body>
</html>